﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using VonaJobs.DAL.DAO;

namespace VonaJobs.DAL.Gatway
{
    public class ApplyGateway:DBGateway
    {
        public string SaveApply(Apply apply)
        {
            try
            {
                ConnectionObj.Open();
                CommandObj.CommandText = string.Format("insert into tblApply values(@ViewApplication,@SeekerId,@JobId,@ApplyDate,@ExpectedSalary,@CoverLatter,@AvailableAfter)");
                CommandObj.Parameters.Clear();
                CommandObj.Parameters.Add("@ViewApplication", SqlDbType.Bit).Value = apply.ViewApplication;
                CommandObj.Parameters.Add("@SeekerId", SqlDbType.Int).Value = apply.Seeker.Id;
                CommandObj.Parameters.Add("@JobId", SqlDbType.Int).Value = apply.Job.Id;
                CommandObj.Parameters.Add("@ApplyDate", SqlDbType.Date).Value = apply.ApplyDate;
                CommandObj.Parameters.Add("@ExpectedSalary", SqlDbType.Decimal).Value = apply.ExpectedSalary;
                CommandObj.Parameters.Add("@CoverLatter", SqlDbType.NVarChar).Value = apply.CoverLatter;
                CommandObj.Parameters.Add("@AvailableAfter", SqlDbType.Int).Value = apply.AvailableAfter;
                CommandObj.ExecuteNonQuery();
                return "Save successfully";
            }
            catch (Exception)
            {
                throw new Exception("Message Not Send, Server Error !");
            }
            finally
            {
                if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
                {
                    ConnectionObj.Close();
                }

            }
        }
    }
}